package com.gin.no_gay_alliance.fragment.main;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.gin.no_gay_alliance.databinding.FragmentMainConfigBinding;
import com.gin.no_gay_alliance.fragment.base.BaseBindingFragment;
import com.gin.no_gay_alliance.fragment.config.ConfigAccountFragment;
import com.gin.no_gay_alliance.fragment.config.ConfigAdvancedFunctionFragment;
import com.gin.no_gay_alliance.fragment.config.ConfigEmoteFragment;
import com.gin.no_gay_alliance.fragment.config.ConfigUiFragment;
import com.gin.no_gay_alliance.fragment.config.ConfigUpgradeFragment;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

public class MainConfigFragment extends BaseBindingFragment<FragmentMainConfigBinding> implements TabLayoutMediator.TabConfigurationStrategy {

    private TabLayoutMediator tabLayoutMediator;

    /**
     * onCreateView 的后续操作
     */
    @Override
    protected void onCreateView() {
        b.vp2.setAdapter(new FragmentStateAdapter(this) {
            @NonNull
            @Override
            public Fragment createFragment(int position) {
                switch (position) {
                    case 0:
                        return new ConfigEmoteFragment();
                    case 1:
                        return new ConfigUiFragment();
                    case 2:
                        return new ConfigAccountFragment();
                    case 3:
                        return new ConfigUpgradeFragment();
                    case 4:
                        return new ConfigAdvancedFunctionFragment();
                    default:
                        throw new RuntimeException("没有那个Fragment");
                }
            }

            @Override
            public int getItemCount() {
                return 5;
            }
        });

        tabLayoutMediator = attachTabLayout(tabLayoutMediator, b.tabLayout, b.vp2);
        b.vp2.setCurrentItem(2);
    }

    /**
     * 配置 TabLayout
     *
     * @param tab      标签
     * @param position 位置
     */
    @Override
    public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
        // 配置每个标签
        switch (position) {
            case 0:
                tab.setText("表情包");
                break;
            case 1:
                tab.setText("界面");
                break;
            case 2:
                tab.setText("账号管理");
                break;
            case 3:
                tab.setText("版本升级");
                break;
            case 4:
                tab.setText("增强功能");
                break;
            default:
                tab.setText("标签");
        }
    }
}